G_DEFINE_AUTOPTR_CLEANUP_FUNC(OtAutoArchiveRead, archive_read_free)
static inline OtAutoArchiveRead *
-ot_open_archive_read (const char *path, GError **error)
+ot_archive_read_new (void)
{
- g_autoptr(OtAutoArchiveRead) a = archive_read_new ();
+ OtAutoArchiveRead *a = archive_read_new ();
#ifdef HAVE_ARCHIVE_READ_SUPPORT_FILTER_ALL
archive_read_support_filter_all (a);
archive_read_support_compression_all (a);
#endif
archive_read_support_format_all (a);
+
+ return a;
+}
+
+static inline OtAutoArchiveRead *
+ot_open_archive_read (const char *path, GError **error)
+{
+ g_autoptr(OtAutoArchiveRead) a = ot_archive_read_new ();
+
if (archive_read_open_filename (a, path, 8192) != ARCHIVE_OK)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "%s", archive_error_string (a));
+ "archive_read_open_filename: %s", archive_error_string (a));
+ return NULL;
+ }
+
+ return g_steal_pointer (&a);
+}
+
+static inline OtAutoArchiveRead *
+ot_open_archive_read_fd (int fd, GError **error)
+{
+ g_autoptr(OtAutoArchiveRead) a = ot_archive_read_new ();
+
+ if (archive_read_open_fd (a, fd, 8192) != ARCHIVE_OK)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "archive_read_open_fd: %s", archive_error_string (a));
return NULL;
}
#endif
}
+#ifdef HAVE_LIBARCHIVE
+static gboolean
+write_archive_to_mtree (OstreeRepo *self,
+ OtAutoArchiveRead *archive,
+ OstreeMutableTree *mtree,
+ OstreeRepoCommitModifier *modifier,
+ gboolean autocreate_parents,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ OstreeRepoImportArchiveOptions opts = { 0, };
+
+ opts.autocreate_parents = !!autocreate_parents;
+
+ if (!ostree_repo_import_archive_to_mtree (self, &opts, archive, mtree, modifier, cancellable, error))
+ goto out;
+
+ if (archive_read_close (archive) != ARCHIVE_OK)
+ {
+ propagate_libarchive_error (error, archive);
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ (void)archive_read_close (archive);
+ return ret;
+}
+#endif
+
/**
* ostree_repo_write_archive_to_mtree:
* @self: An #OstreeRepo
GError **error)
{
#ifdef HAVE_LIBARCHIVE
- gboolean ret = FALSE;
- g_autoptr(OtAutoArchiveRead) a = archive_read_new ();
- OstreeRepoImportArchiveOptions opts = { 0, };
-
- a = ot_open_archive_read (gs_file_get_path_cached (archive), error);
- if (!a)
- goto out;
- opts.autocreate_parents = !!autocreate_parents;
-
- if (!ostree_repo_import_archive_to_mtree (self, &opts, a, mtree, modifier, cancellable, error))
- goto out;
+ g_autoptr(OtAutoArchiveRead) a = ot_open_archive_read (gs_file_get_path_cached (archive), error);
+ if (a)
+ return write_archive_to_mtree (self, a, mtree, modifier, autocreate_parents, cancellable, error);
- if (archive_read_close (a) != ARCHIVE_OK)
- {
- propagate_libarchive_error (error, a);
- goto out;
- }
+ return FALSE;
+#else
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "This version of ostree is not compiled with libarchive support");
+ return FALSE;
+#endif
+}
- ret = TRUE;
- out:
+/**
+ * ostree_repo_write_archive_to_mtree_from_fd:
+ * @self: An #OstreeRepo
+ * @fd: A file descriptor to read the archive from
+ * @mtree: The #OstreeMutableTree to write to
+ * @modifier: (allow-none): Optional commit modifier
+ * @autocreate_parents: Autocreate parent directories
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Read an archive from @fd and import it into the repository, writing
+ * its file structure to @mtree.
+ */
+gboolean
+ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo *self,
+ int fd,
+ OstreeMutableTree *mtree,
+ OstreeRepoCommitModifier *modifier,
+ gboolean autocreate_parents,
+ GCancellable *cancellable,
+ GError **error)
+{
+#ifdef HAVE_LIBARCHIVE
+ g_autoptr(OtAutoArchiveRead) a = ot_open_archive_read_fd (fd, error);
if (a)
- {
- (void)archive_read_close (a);
- }
- return ret;
+ return write_archive_to_mtree (self, a, mtree, modifier, autocreate_parents, cancellable, error);
+
+ return FALSE;
#else
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"This version of ostree is not compiled with libarchive support");